package com.bawei.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.bawei.model.Repertory;
import com.bawei.service.RepertoryService;
import com.bawei.util.JsonUtil;
import com.bawei.util.Jsonutils;

@RestController
@CrossOrigin(origins="*")
@RequestMapping("/repertory/")
public class RepertoryController {
	@Autowired
	private RepertoryService repertoryService;
	
	@RequestMapping("getRepertory")
	public Jsonutils getRepertory(Repertory repertory) {
		Map map = new HashMap();
		if(repertory.getgCodeMohu()!=null&&!repertory.getgCodeMohu().trim().equals(""))
			map.put("gCodeMohu",repertory.getgCodeMohu());
		if(repertory.getgNameMohu()!=null&&!repertory.getgNameMohu().trim().equals(""))
			map.put("gNameMohu",repertory.getgNameMohu());
		if(repertory.getSkuMohu()!=null&&!repertory.getSkuMohu().trim().equals(""))
			map.put("skuMohu",repertory.getSkuMohu());
		if(repertory.getGoodsNameMohu()!=null&&!repertory.getGoodsNameMohu().trim().equals(""))
			map.put("goodsName",repertory.getGoodsNameMohu());
		List<Repertory> list = repertoryService.getRepertory(map);
		return Jsonutils.success(list);
	}	
	
	@RequestMapping("getRepertoryById")
	public String getRepertoryById(String id) {
		return JsonUtil.success(repertoryService.getRepertoryById(Long.valueOf(id)));
	}
	
	@RequestMapping("addRepertory")
	public String addRepertory(Repertory repertory) {
		repertoryService.addRepertory(repertory);
		return JsonUtil.success();
	}
	
	@RequestMapping("delRepertory")
	public String delRepertory(String id) {
		repertoryService.delRepertory(Long.valueOf(id));
		return JsonUtil.success();
	}
	
	@RequestMapping("updateRepertory")
	public String updateRepertory(Repertory repertory) {
		repertoryService.updateRepertory(repertory);
		return JsonUtil.success();
	}
	//getRepertoryByCondition
	@RequestMapping("getRepertoryByCondition")
	public String getRepertoryByCondition(Repertory repertory) {
		return JsonUtil.success(repertoryService.getRepertoryByCondition(repertory));
	}
	@RequestMapping("rk")
	public String rk(Repertory repertory) {
		repertoryService.rk(repertory);
		return JsonUtil.success();
	}
	
	@RequestMapping("ck")
	public String ck(Repertory repertory) {
		repertoryService.ck(repertory);
		return JsonUtil.success();
	}
	
	@RequestMapping("relAdd")
	public String relAdd(Repertory repertory) {
		repertoryService.relAdd(repertory);
		return JsonUtil.success();
	}
	
	//updaterepertoryType
	@RequestMapping("updaterepertoryType")
	public String updaterepertoryType(Repertory repertory) {
		repertoryService.updaterepertoryType(repertory.getId());
		return JsonUtil.success();
	}
	@RequestMapping("updaterepertoryTypeNo")
	public String updaterepertoryTypeNo(String id) {
		repertoryService.updaterepertoryTypeNo(Long.valueOf(id));
		return JsonUtil.success();
	}
}
